From cd869ef636476ffffd1510e9c3001f7017d8687d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 13 Jan 2015 21:23:43 -0800 Subject: [PATCH] Remove auto-cleaning of the build directory Over time this functionality has become obsolete through other means. Due to the usage of `-L dependency=foo` it's not possible to pick up stale dependencies by accident, and due to `--extern` you can only pick up a dependency. All of the cases that auto-cleaning was fixing are now fixed through other methods, so there's not much use ensuring a "clean build directory" any more. This has the benefit of fixing issues like #961 where the downside of long compiles outweighs the benefits of a "let's pretend we started from scratch" build. Closes #961 --- src/cargo/ops/cargo_rustc/fingerprint.rs | 7 +-- src/cargo/ops/cargo_rustc/layout.rs | 67 ++++-------------------- src/cargo/ops/cargo_rustc/mod.rs | 4 -- tests/test_cargo_compile_path_deps.rs | 7 +-- tests/test_cargo_test.rs | 21 ++++++++ 5 files changed, 36 insertions(+), 70 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index 297173a31..7fc4a13dc 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -46,7 +46,6 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>, pkg.get_package_id(), target)); let new = dir(cx, pkg, kind); let loc = new.join(filename(target)); - cx.layout(pkg, kind).proxy().whitelist(&loc); info!("fingerprint at: {}", loc.display()); @@ -58,7 +57,6 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>, if !target.get_profile().is_doc() { for filename in try!(cx.target_filenames(target)).iter() { let dst = root.join(filename); - cx.layout(pkg, kind).proxy().whitelist(&dst); missing_outputs |= !dst.exists(); if target.get_profile().is_test() { @@ -236,7 +234,6 @@ pub fn prepare_build_cmd(cx: &mut Context, pkg: &Package, kind: Kind, pkg.get_package_id())); let new = dir(cx, pkg, kind); let loc = new.join("build"); - cx.layout(pkg, kind).proxy().whitelist(&loc); info!("fingerprint at: {}", loc.display()); @@ -305,9 +302,7 @@ pub fn dir(cx: &Context, pkg: &Package, kind: Kind) -> Path { /// Returns the (old, new) location for the dep info file of a target. pub fn dep_info_loc(cx: &Context, pkg: &Package, target: &Target, kind: Kind) -> Path { - let ret = dir(cx, pkg, kind).join(format!("dep-{}", filename(target))); - cx.layout(pkg, kind).proxy().whitelist(&ret); - return ret; + dir(cx, pkg, kind).join(format!("dep-{}", filename(target))) } fn is_fresh(loc: &Path, new_fingerprint: &Fingerprint) -> CargoResult { diff --git a/src/cargo/ops/cargo_rustc/layout.rs b/src/cargo/ops/cargo_rustc/layout.rs index 87af32150..db98584be 100644 --- a/src/cargo/ops/cargo_rustc/layout.rs +++ b/src/cargo/ops/cargo_rustc/layout.rs @@ -45,11 +45,8 @@ //! .fingerprint/ //! ``` -use std::cell::RefCell; -use std::collections::HashSet; use std::old_io::fs::PathExtensions; use std::old_io::{self, fs, IoResult}; -use std::mem; use core::Package; use util::hex::short_hash; @@ -61,7 +58,6 @@ pub struct Layout { build: Path, fingerprint: Path, examples: Path, - to_delete: RefCell>, } pub struct LayoutProxy<'a> { @@ -91,7 +87,6 @@ impl Layout { fingerprint: root.join(".fingerprint"), examples: root.join("examples"), root: root, - to_delete: RefCell::new(HashSet::new()), } } @@ -100,34 +95,16 @@ impl Layout { try!(fs::mkdir_recursive(&self.root, old_io::USER_RWX)); } - try!(mkdir(self, &self.deps, false)); - try!(mkdir(self, &self.native, false)); - try!(mkdir(self, &self.fingerprint, true)); - try!(mkdir(self, &self.examples, false)); - try!(mkdir(self, &self.build, false)); - - for file in try!(fs::readdir(&self.root)).into_iter() { - if !file.is_file() { continue } - - self.to_delete.borrow_mut().insert(file); - } + try!(mkdir(&self.deps)); + try!(mkdir(&self.native)); + try!(mkdir(&self.fingerprint)); + try!(mkdir(&self.examples)); + try!(mkdir(&self.build)); return Ok(()); - fn mkdir(layout: &Layout, dir: &Path, deep: bool) -> IoResult<()> { - if dir.exists() { - if deep { - for file in try!(fs::walk_dir(dir)) { - if !file.is_dir() { - layout.to_delete.borrow_mut().insert(file); - } - } - } else { - for file in try!(fs::readdir(dir)).into_iter() { - layout.to_delete.borrow_mut().insert(file); - } - } - } else { + fn mkdir(dir: &Path) -> IoResult<()> { + if !dir.exists() { try!(fs::mkdir(dir, old_io::USER_DIR)); } Ok(()) @@ -140,44 +117,20 @@ impl Layout { // TODO: deprecated, remove pub fn native(&self, package: &Package) -> Path { - let ret = self.native.join(self.pkg_dir(package)); - self.whitelist(&ret); - ret + self.native.join(self.pkg_dir(package)) } pub fn fingerprint(&self, package: &Package) -> Path { - let ret = self.fingerprint.join(self.pkg_dir(package)); - self.whitelist(&ret); - ret + self.fingerprint.join(self.pkg_dir(package)) } pub fn build(&self, package: &Package) -> Path { - let ret = self.build.join(self.pkg_dir(package)); - self.whitelist(&ret); - ret + self.build.join(self.pkg_dir(package)) } pub fn build_out(&self, package: &Package) -> Path { self.build(package).join("out") } - pub fn clean(&self) -> IoResult<()> { - let set = mem::replace(&mut *self.to_delete.borrow_mut(), - HashSet::new()); - for file in set.iter() { - info!("dirty: {}", file.display()); - if file.is_dir() { - try!(fs::rmdir_recursive(file)); - } else { - try!(fs::unlink(file)); - } - } - Ok(()) - } - - pub fn whitelist(&self, p: &Path) { - self.to_delete.borrow_mut().remove(p); - } - fn pkg_dir(&self, pkg: &Package) -> String { format!("{}-{}", pkg.get_name(), short_hash(pkg.get_package_id())) } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 4f097c387..0e81545b7 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -183,10 +183,6 @@ pub fn compile_targets<'a, 'b>(env: &str, try!(compile(targets, pkg, true, &mut cx, &mut queue)); - // Clean out any old files sticking around in directories. - try!(cx.layout(pkg, Kind::Host).proxy().clean()); - try!(cx.layout(pkg, Kind::Target).proxy().clean()); - // Now that we've figured out everything that we're going to do, do it! try!(queue.execute(cx.config)); diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index 31d3ad185..9286d7ed2 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -1,4 +1,5 @@ -use std::old_io::{fs, File, USER_RWX}; +use std::old_io::{fs, File, USER_RWX, timer}; +use std::time::Duration; use support::{project, execs, main_file, cargo_dir}; use support::{COMPILING, RUNNING}; @@ -353,7 +354,7 @@ test!(deep_dependencies_trigger_rebuild { // // We base recompilation off mtime, so sleep for at least a second to ensure // that this write will change the mtime. - p.root().move_into_the_past().unwrap(); + timer::sleep(Duration::seconds(1)); File::create(&p.root().join("baz/src/baz.rs")).write_str(r#" pub fn baz() { println!("hello!"); } "#).unwrap(); @@ -366,7 +367,7 @@ test!(deep_dependencies_trigger_rebuild { COMPILING, p.url()))); // Make sure an update to bar doesn't trigger baz - p.root().move_into_the_past().unwrap(); + timer::sleep(Duration::seconds(1)); File::create(&p.root().join("bar/src/bar.rs")).write_str(r#" extern crate baz; pub fn bar() { println!("hello!"); baz::baz(); } diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 4edd7922e..e9279d8eb 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1311,3 +1311,24 @@ test!(example_with_dev_dep { {running} `rustc [..] --crate-name ex [..] --extern a=[..]` ", running = RUNNING).as_slice())); }); + +test!(bin_is_preserved { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/lib.rs", "") + .file("src/main.rs", "fn main() {}"); + + assert_that(p.cargo_process("build").arg("-v"), + execs().with_status(0)); + assert_that(&p.bin("foo"), existing_file()); + + println!("testing"); + assert_that(p.process(cargo_dir().join("cargo")).arg("test").arg("-v"), + execs().with_status(0)); + assert_that(&p.bin("foo"), existing_file()); +}); -- 2.30.2